﻿using DCIMAP.GANS.GeneticAlgorithms;
using DCIMAP.GANS.GeneticAlgorithms.Kit;
using System;

using DCIMAP.GANS.GeneticAlgorithms.Legacy;

[System.Serializable]
public class IQCrosser : Crosser
{
    
    public override Gene Cross(Gene mother, Gene father)
    {
        StringArrayGene m = (StringArrayGene)mother;
        StringArrayGene f = (StringArrayGene)father;
        StringArrayGene son = (StringArrayGene)m.CreateEmpty();
        if (m.Code.Length != f.Code.Length || m.Code.Length != son.Code.Length)
            throw new Exception("All lengthes must be the same");

        int rn = Algorithm.Random.Next(m.Code.Length);


        for (int i = 0; i < rn; i++)
        {
            
            son.StringCode[i] = m.StringCode[i];
        }
        for (int i = rn; i < son.Code.Length; ++i)
        {
            son.StringCode[i] = f.StringCode[i];
        }
        return son;
    }
}
